import type { IProgram, IProgramStatus } from "@/lib/types";
import { getProgramStatusSummary } from "@/lib/utils/getProgramStatusSummary";
import { useMemo } from "react";

type ProgramSummaryProps = {
  program?: IProgram | null;
  status?: IProgramStatus[] | null;
};

export default function ProgramSummary(props: ProgramSummaryProps) {
  const { program, status } = props;

  const summary = useMemo(() => {
    if (!status || !program?.loop) {
      return { totalTime: "-", totalSteps: "-" };
    }
    return getProgramStatusSummary(status, program.loop);
  }, [status, program?.loop]);

  return (
    <div className="my-4 flex-none rounded bg-[#262626] px-4 py-2 text-sm">
      <span className="mr-4">{program?.programName || "-"}</span>
      <span className="mr-4">总时间：{summary.totalTime}</span>
      <span className="mr-4">总步数：{summary.totalSteps}</span>
      <span className="mr-4">循环数：{program?.loop || "-"}</span>
    </div>
  );
}
